package com.zsh.wx_account1.controller;

import com.zsh.wx_account1.util.HttpUtil;
import com.zsh.wx_account1.util.TokenUtil;
import org.junit.jupiter.api.Test;

/**
 * 素材管理
 * @Author ZhaoShuHao
 * @Date 2023/8/25 11:40
 */
public class TestMaterialManagement {
    //上传临时素材
    @Test
    public void testImage(){
        //这里上传了一个图片
        String url = String.format("https://api.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s",
                TokenUtil.getAccessToken(),
                "image");
        String result = HttpUtil.doPostByFile(url, null, "src/main/resources/static/image/image1.jpg", "");
        System.out.println(result);
//{"type":"image","media_id":"gw-BxwWm3mP6T2M_OBR1IzPwl6YcFFncr4fx3CrS-wtJOd78l7evdmUm5e3b2BZP","created_at":1692935476,"item":[]}
    }

    /*
    图片地址：https://api.weixin.qq.com/cgi-bin/media/get?access_token=token的值&media_id=图片id
    https://api.weixin.qq.com/cgi-bin/media/get?access_token=71_3PiSMSASfd1s9s5CFK30XX3CaG3IamKRjT25tmfShuk4i2I3y3Ze0ebR0SSES-hro5T7zO5YVEo0pWiaedG3Yv5y4qRcoETPNRbqJJKOYxpH5ac_rD3CPtfCuZQTGGdAIAYLL&media_id=gw-BxwWm3mP6T2M_OBR1IzPwl6YcFFncr4fx3CrS-wtJOd78l7evdmUm5e3b2BZP
     */

    //获得临时素材
    @Test
    public void testGetImage(){
        String mediaId = "gw-BxwWm3mP6T2M_OBR1IzPwl6YcFFncr4fx3CrS-wtJOd78l7evdmUm5e3b2BZP";
        String url = String.format("https://api.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s",
                TokenUtil.getAccessToken(),
                mediaId);
        String result = HttpUtil.doGet(url);
        System.out.println(result);

    }
}
